/**
 * 
 */
package ac.uk.qmul.gemom.scenario;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.tree.DefaultMutableTreeNode;

/*
 * A class used for storing publisher's behavious as their settings
 * 
 * COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 */
public class PublisherSetting {
	public int id;
	public String system_start_time;
	//public ArrayList<TimeSeg> tsegs;
	public ArrayList<ArrayList<TimeSeg>> tasks;

//	public String[] tags =  {"id","time_segment"};
	
	PublisherSetting(){
//		configs = new ArrayList<HashMap>();
		tasks = new ArrayList<ArrayList<TimeSeg>>(); 
/*		if(n.toString().equals("publisher")){
			
			Vector<DefaultMutableTreeNode> l=new Vector<DefaultMutableTreeNode>();
						
			l.removeAllElements();	
			fileParser.findNode(tags[0],n, l);
			id=Integer.parseInt(l.get(0).getFirstLeaf().toString());
			
			l.removeAllElements();	
			fileParser.findNode(tags[1],n,l);
			for (DefaultMutableTreeNode a :l){
//				each time_segment node
				if (a.getChildCount() > 0) {
					HashMap<String, String> tsMap = new HashMap();
					for (Enumeration<DefaultMutableTreeNode> e=a.children(); e.hasMoreElements(); ){
						DefaultMutableTreeNode b= e.nextElement();
						tsMap.put(b.toString(),b.getFirstLeaf().toString());
						
					}
					configs.add(tsMap);
				}
			}
			
			
		}*/
	}
	
	// return the list of time sgements'm settings of a particular Task set
	public ArrayList<TimeSeg> getTask(int index){
		return tasks.get(index);
	}
	
	public int getTaskNum(){
		return tasks.size();
	}
	
	// add a new task to the publisher's scenario configuration, a task is a collection of
	// publisher behaviors defined in an array of Timeseg class objects 
	public void addTask(int taskId){
	    tasks.add(new ArrayList<TimeSeg>());	
	}
	
	// add a Time Segments' definition into the scenario 
	public void addSegByTask(int taskId, TimeSeg seg){
	    if(tasks.get(taskId) != null){
	    	tasks.get(taskId).add(seg);
	    }
	}
	
}

class TimeSeg{
	TimeSeg(){
		publish_list = new ArrayList<String>();
	}
//	the parameters in a time segment 
	public int t_id;
	public double time_start;
	public double time_stop;
	public String distribution;
	public String message_length_distribution;
	public int message_length;
	public double mld_std_deviation;
	public String ingressNode;
	public double mean_rate;
	public double min_rate;
	public double max_rate;
	public boolean use_mean_rate;
	public String topicns;
	public String fault_pattern;
	public ArrayList<String> publish_list;
	public double mean_delay;
	public String delay_distribution;
//	public int rate_max;
//	public int rate_min;
}












